package com.ys.util.dhecp;

import java.math.BigDecimal;

/**
 * @ClassName MathExtUtils
 * @Description TODO
 * @Author alula
 * @Date 2022-12-09 14:38
 */
public class MathExtUtils {
    public static double fmtPrice(double price) {
        return fmtPrice(price, 2);
    }

    public static double fmtPrice(double price, int pos) {
        if (price > 0.0D) {
            BigDecimal b = new BigDecimal(price);
            return b.setScale(pos, BigDecimal.ROUND_HALF_UP).doubleValue();
        }
        return 0.0D;
    }

    public static int fmtIntPrice(double price) {
        if (price > 0.0D) {
            BigDecimal b = new BigDecimal(price);
            return b.setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
        }
        return 0;
    }

    public static BigDecimal fmtDecimalPrice(BigDecimal price, int pos){
        return price.setScale(pos, BigDecimal.ROUND_HALF_UP);
    }
}
